/*
Given a linked list, determine if it has a cycle in it.

Follow up:
Can you solve it without using extra space?

 */


#include <iostream>
#include <vector>
#include <bits/stl_algo.h>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <regex>


using namespace std;


struct ListNode {
    int val;
    ListNode *next;
    ListNode(int x) : val(x), next(NULL) {}
};


class Solution {
public:
    bool hasCycle(ListNode *head) {
        if (head == nullptr || head->next == nullptr){
            return false;
        }

        auto slow = head;
        auto fast = head->next;

        while (slow && fast && fast->next){
            if (slow == fast){
                return true;
            }
            slow = slow->next;
            fast = fast->next->next;
        }
        return false;
    }
};



int main(){

}